﻿using System.Data;

namespace Dz.WorkerService.Utils
{
    internal class WarehouseUtils : BaseUtils
    {
        private Dictionary<string,string> whs = new Dictionary<string, string>();

        private static readonly Lazy<WarehouseUtils> instance = new Lazy<WarehouseUtils>(() => new WarehouseUtils());

        public static WarehouseUtils Instance => instance.Value;


        protected override void Init()
        {
            string sql = @"select a.code , b.code as org
                        from cbo_wh a
                        inner join Base_Organization b on a.org = b.ID
                        where lower(a.DescFlexField_PrivateDescSeg2)='true'";

            DataTable reader = sqlUtils.FillSync(sql);

            foreach (DataRow row in reader.Rows)
            {
                whs.Add(row[1].ToString(), row[0].ToString());
            }
        }

        public string GetRtnWh(string org)
        {
            if(whs.ContainsKey(org)) return whs[org];

            return string.Empty;
        }

        public override void ReLoad()
        {
            whs.Clear();
            Init();
        }
    }
}
